package com.just.fun.map;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

public class MapTest {
    public static void main(String[] args){
        //测试不同遍历方式效率
        Map<String,Integer> map=new LinkedHashMap<>(1000000);
        for(int i=0;i<1000000;i++){
            map.put(String.valueOf(i),i);
        }

        //for each
        long start1=System.currentTimeMillis();
        for(Map.Entry<String,Integer> entry:map.entrySet()){

        }
        System.out.println("entrySet时间："+(System.currentTimeMillis()-start1));

        long start2=System.currentTimeMillis();
        Iterator<Map.Entry<String,Integer>> it=map.entrySet().iterator();
        while (it.hasNext()){
            it.next();
        }
        System.out.println("iterator时间："+(System.currentTimeMillis()-start2));

        long start3=System.currentTimeMillis();
        map.forEach((key,value)->{
        });
        System.out.println("java8的forEach时间："+(System.currentTimeMillis()-start3));
    }
}
